//
//  ModelQues.m
//  解压缩&解析数据
//
//  Created by 盛超 on 2018/8/21.
//  Copyright © 2018年 盛超. All rights reserved.
//

#import "ModelQues.h"

@implementation ModelQues

+ (NSDictionary *)modelContainerPropertyGenericClass {
    return @{
             @"ImportantZSD":[ZSD class],
             @"MainZSD":[ZSD class],
             @"AudioList":[AVdio class],
             @"VedioList":[AVdio class],
             @"ChildList":[Child class]
             };
}

- (instancetype)initWithDict:(NSDictionary *)dict Type:(LSQuestionType)type {
    if (self = [super init]) {
        //听力题
        if (type==LSListeningTest) {
            
            self.QuesBody = dict[@"QuesStem"][@"question"][@"DisplayContent"];
            
            AVdio *audio = [[AVdio alloc] init];
            audio.AudioPath = dict[@"QuesStem"][@"question"][@"Audio"][@"Resource"][@"__text"];
            audio.Article = dict[@"QuesStem"][@"question"][@"Audio"][@"Resource"][@"_Text"];
            self.AudioList = [NSArray arrayWithObject:audio];
            self.TimeLong = ((NSNumber*)dict[@"QuesStem"][@"question"][@"Audio"][@"Resource"][@"_length"]).integerValue;
            
            NSMutableArray *arr = [NSMutableArray array];
            NSArray *childArr = dict[@"QuesArray"][@"question"];
            for (NSInteger i = 0; i<childArr.count; i++) {
                Child *child = [[Child alloc] init];
                NSDictionary *childDict = childArr[i];
                child.ChildIndex = i+1;
                child.ChildAnswerType = 1;
                child.ChildAsk = childDict[@"issure"];
                child.ChildAnswer = childDict[@"Answer"][@"Resource"][@"__text"];
                child.ChildAnalyze = childDict[@"Analysis"][@"Resource"][@"__text"];
                
                NSMutableArray *arr2 = [NSMutableArray array];
                NSArray *optinArr = childDict[@"option"];
                for (NSInteger j = 0; j<optinArr.count; j++) {
                    Option *option = [[Option alloc] init];
                    NSDictionary *optionDict = optinArr[j];
                    option.OptionIndex = [NSString stringWithFormat:@"%c",(int)(j+65)];
                    option.OptionContent = optionDict[@"optxt"];
                    [arr2 addObject:option];
                }
                child.ChildOptionList = [NSArray arrayWithArray:arr2];
                [arr addObject:child];
            }
            self.ChildList = [NSArray arrayWithArray:arr];
            self.TotalItemCount = self.ChildList.count;
            //        NSString *tring =  [ques yy_modelToJSONString];
            //        NSLog(@"%@",tring);
            
        } else if (type == LSReadingTest) { //朗读题
            
            self.QuesBody = dict[@"QuesArray"][@"question"][@"DisplayContent"];
            Child *child = [[Child alloc] init];
            child.ChildIndex = 1;
            child.ChildAnswer = dict[@"QuesArray"][@"question"][@"Answer"][@"Resource"][@"__text"];
            child.ChildAnalyze = dict[@"QuesArray"][@"question"][@"Analysis"][@"Resource"][@"__text"];
            self.ChildList = [NSArray arrayWithObject:child];
            self.TotalItemCount = 1;
            
            //        NSString *tring =  [ques yy_modelToJSONString];
            //        NSLog(@"%@",tring);
            
        } else if (type == LSFollowSpeakingTest) {  //跟读题
            
            self.QuesBody = dict[@"QuesArray"][@"question"][@"DisplayContent"];
            
            Child *child = [[Child alloc] init];
            child.ChildIndex = 1;
            child.ChildAnswer = dict[@"QuesArray"][@"question"][@"Answer"][@"Resource"][@"__text"];
            child.ChildAnalyze = dict[@"QuesArray"][@"question"][@"Analysis"][@"Resource"][@"__text"];
            self.ChildList = [NSArray arrayWithObject:child];
            self.TotalItemCount = 1;
            
            AVdio *audio = [[AVdio alloc] init];
            audio.AudioPath = dict[@"QuesArray"][@"question"][@"Audio"][@"Resource"][@"__text"];
            audio.Article = dict[@"QuesArray"][@"question"][@"Audio"][@"Resource"][@"_Text"];
            self.AudioList = [NSArray arrayWithObject:audio];
            self.TimeLong = ((NSNumber*)dict[@"QuesStem"][@"question"][@"Audio"][@"Resource"][@"_length"]).integerValue;
            
            //        NSString *tring =  [ques yy_modelToJSONString];
            //        NSLog(@"%@",tring);
        }

    }
    return self;
}


@end

@implementation ZSD

@end

@implementation AVdio

@end

@implementation Child

+ (NSDictionary *)modelContainerPropertyGenericClass {
    return @{
             @"ChildStemList":[Stem class],
             @"ChildOptionList":[Option class],
             };
}

@end

@implementation Stem

@end

@implementation Option

@end


